package chef.myapplication.model;

import javafx.scene.control.Alert;
import javafx.scene.control.ButtonBar;
import javafx.scene.control.ButtonType;
import javafx.stage.Window;

import java.util.Optional;

public class MyAlert {

	 public static boolean showAlert1(String p_header,String p_message,Window stage){
       Alert alert = new Alert(Alert.AlertType.CONFIRMATION,p_message,new ButtonType("取消", ButtonBar.ButtonData.NO),
               new ButtonType("确定", ButtonBar.ButtonData.YES));
         return setAlert(p_header, stage, alert);
     }

    private static boolean setAlert(String p_header, Window stage, Alert alert) {
        alert.setTitle("注意窗口");
        alert.setHeaderText(p_header);
        alert.initOwner(stage);
        Optional<ButtonType> buttonType = alert.showAndWait();
        if(buttonType.get().getButtonData().equals(ButtonBar.ButtonData.YES)){
            return true;
        }
        else {
            return false;
        }
    }

    public static boolean showAlert2(String p_header,String p_message,Window stage){
       Alert alert = new Alert(Alert.AlertType.CONFIRMATION,p_message,new ButtonType("创建副本", ButtonBar.ButtonData.NO),
               new ButtonType("确定", ButtonBar.ButtonData.YES));
        return setAlert(p_header, stage, alert);
    }
}
